/*
 *  Copyright 2008-2010 www.jrails.org
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package org.rails.extjs.menu;

import org.rails.extjs.Option;
import org.rails.extjs.javascript.Function;

public class Item extends BaseItem {

	public Item() {
		super();
	}

	public Item(Option configOptions) {
		super(configOptions);
	}

	public Item(String id) {
		super(id);
	}
	
	public Item(String text,String icon,Function handler) {
		super();
		setText(text);
		setIcon(icon);
		setHandler(handler);
	}
	
	public Boolean isCanActivate(){
		return getBoolean("canActivate",true);
	}
	
	public void setHref(String href){
		addOption("href", href);
	}
	
	public String getHref(){
		return getString("href","#");
	}
	
	public void setHrefTarget(String hrefTarget){
		addOption("hrefTarget", hrefTarget);
	}
	
	public String getHrefTarget(){
		return getString("hrefTarget","");
	}
	
	public void setIcon(String icon){
		addOption("icon", icon);
	}
	
	public String getIcon(){
		return getString("icon","");
	}
	
	public void setIconClass(String iconCls){
		addOption("iconCls", iconCls);
	}
	
	public String getIconClass(){
		return getString("iconCls", "");
	}
	
	public void setMenu(Menu menu){
		addOption("menu",menu);
	}
	
	public Menu getMenu(){
		return (Menu)getOption("menu");
	}
	
	public void setShowDelay(Integer showDelay){
		addOption("showDelay", showDelay);
	}
	
	public Integer getShowDelay(){
		return getInteger("showDelay",200);
	}
	
	public void setText(String text){
		addOption("text", text);
	}
	
	public String getText(){
		return getString("text","");
	}

	@Override
	public String getScript() {
		script = new StringBuffer("");
		createItems();
		script.append("new Ext.menu.Item(");
		script.append(createOptions());
		script.append(")");
		return script.toString();
	}

}
